package com.example.rbacmanage.service.impl;

import com.example.rbacmanage.entity.Post;
import com.example.rbacmanage.exception.MyException;
import com.example.rbacmanage.service.PostService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.example.rbacmanage.mapper.PostMapper;

import java.util.Date;
import java.util.List;

/**
 * 岗位服务实现类
 *
 * @author zmd
 */
@Service
public class PostServiceImpl  implements PostService {
    @Autowired
    private PostMapper  postMapper;

    @Override
    public void save(Post post) {
        post.setCreateTime(new Date());
        postMapper.insert(post);
    }

    @Override
    public void remove(Long[] ids) {
        for(Long id:ids){
                postMapper.del(id);
        }
    }

    @Override
    public void update(Post post) {
            postMapper.update(post);
    }

    @Override
    public List<Post> getAll(Post post) {
        return postMapper.list(post);
    }

    @Override
    public PageInfo<Post> getPage(Post post) {
        PageHelper.startPage(post.getPage(), post.getLimit());
        return new PageInfo<>(postMapper.list(post));
    }

    @Override
    public Post getById(Long id) {
        return postMapper.queryOneById(id);
    }

    @Override
    public Integer getCount(Post post) {
        return postMapper.count(post);
    }

    @Override
    public void checkRepeat(Post post) throws MyException {

    }
}
